home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
qbnws105.zip
/
QBFORMAT.ZIP
/
QBFORMAT.BAS
< prev
Wrap
BASIC Source File
|
1990-10-25
|
17KB
|
525 lines
DECLARE FUNCTION QBFORMAT% (drive%, media%)
DECLARE FUNCTION FormatDisk% (drive%)
DECLARE FUNCTION FormatTrack% (drive%, track%, head%)
DECLARE FUNCTION ValidateDisk% (drive%, media%)
DECLARE FUNCTION WriteBoot% (drive%)
DECLARE FUNCTION WriteDir% (drive%)
DECLARE FUNCTION WriteFAT% (drive%)
DECLARE FUNCTION WriteSector% (drive%, cyl%, hd%, sec%)
DECLARE FUNCTION WriteBootSector% (drive%)
DECLARE SUB ComputeCHS (LogSec%, cyl%, hd%, sec%)
DECLARE SUB InitFormatParms (media%)
DECLARE SUB ResetFDC (drive%)
'QBFORMAT.BAS by Cornel Huth 31-Oct-90
'format MS-DOS floppy disks using QB and BIOS
'requires QB.QLB/QB.LIB (specifically INTERRUPTX())
'{5.25-inch media types supported in this code}
'{DS9=double-sided 9-sector(360K) DS15=double-sided 15-sector (1.2M)}
CONST DS9 = &HFD, DS15 = &HF9
'{3.5-inch media types partially supported in this code}
'{DX9=double-sided 9-sector(720K) DX18=double-sided 18-sector (1.44M)}
'{*** DX9 media byte is NEGATIVE to differ from DS15 ***}
CONST DX9 = -&HF9, DX18 = &HF0
CONST RETRIES = 3 '{retries on BIOS error}
TYPE REGtypeX
ax AS INTEGER
bx AS INTEGER
cx AS INTEGER
dx AS INTEGER
bp AS INTEGER
si AS INTEGER
di AS INTEGER
flags AS INTEGER
ds AS INTEGER
es AS INTEGER
END TYPE '20
TYPE ADDRFIELDtype
track AS STRING * 1
head AS STRING * 1
sector AS STRING * 1
bytesec AS STRING * 1
END TYPE '4
TYPE INFOtype
OEM AS STRING * 8 'system name
BS AS INTEGER 'bytes/sector
SC AS STRING * 1 'sectors/cluster
RS AS INTEGER 'reserved sectors
NF AS STRING * 1 'FATs
DE AS INTEGER 'root directory entries
TS AS INTEGER 'total sectors on volume
MB AS STRING * 1 'media byte
SF AS INTEGER 'sectors/FAT
ST AS INTEGER 'sectors/track
NH AS INTEGER 'heads
HS AS INTEGER 'hidden sectors
END TYPE '27
TYPE BOOTRECtype
jmp AS STRING * 3
parms AS INFOtype
code AS STRING * 482
END TYPE '512
'{External routine included with QB 4.0 in QB.LIB & QB.QLB}
'{The INTRPT.ASM supplied with QB 4.00 has 2 known bugs, one of}
'{which is so bad that this code cannot work properly with it.}
'{The INTRPT.ASM supplied with QB 4.00b has 1 known bug, this}
'{code will work with it but DOS BIOS INT25/26h calls will not.}
'{Later versions may still have that bug!}
DECLARE SUB INTERRUPTX (intnum%, ireg AS REGtypeX, oreg AS REGtypeX)
DEFINT A-Z
'{INT 1Eh disk parameter table vectors}
DIM SHARED OldDPTseg, OldDPToff
DIM SHARED NewDPTseg, NewDPToff
'{Number of tracks on media}
DIM SHARED NoTracks
'{format info for media}
DIM SHARED Info AS INFOtype
'{interface with INTERRUPTX routine}
DIM SHARED ireg AS REGtypeX, oreg AS REGtypeX
'{boot record buffer}
DIM SHARED BootRec AS BOOTRECtype
'{sector buffer to write FAT & root directory sectors}
DIM SHARED SectorBuff AS STRING * 512
REM $STATIC
'{Allocate address field data to max possible sectors per track}
DIM SHARED AddrField(1 TO 18) AS ADDRFIELDtype
BootSector:
DATA &HEB,&H3E,&H90,&H20,&H20,&H20,&H20,&H20,&H20,&H20,&H20,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &HA,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H2B,&HC0,&H8E,&HD0,&HBC,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H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0
DATA &H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H0,&H55,&HAA
'============================================================================
'{The following code is a sample run to format a disk}
'{All other code can be compiled and put in a library}
'{format test drive A: double-sided/9-sector media (360K)}
'{...and you thought that this was going to be hard}
drive = 0: media = DS9
CLS : DO: LOOP WHILE INKEY$ <> ""
INPUT "Insert DS9 disk to format in drive A: and press a key", a$
INPUT "Press a key to start QBFORMAT", a$
PRINT "formatting..."
xerr = QBFORMAT(drive, media)
IF xerr THEN
errl = xerr \ 256
errc = xerr AND 255
PRINT "*** Error level:"; errl; " code:"; errc
ELSE
PRINT "done."
END IF
STOP
SUB ComputeCHS (LogSec, cyl, hd, sec)
'{convert a DOS logical sector to BIOS form}
CylSec = Info.ST * Info.NH
cyl = LogSec \ CylSec
rm = LogSec - (cyl * CylSec)
hd = rm \ Info.ST
sec = rm - (hd * Info.ST) + 1
END SUB
FUNCTION FormatDisk (drive)
'{format a track at a time a side at a time}
'{any error aborts format,diskette presumed unreliable}
'{retry format 1 or 2 more times before trashing the diskette}
FOR track = 0 TO (NoTracks - 1)
FOR head = 0 TO (Info.NH - 1)
FOR i = 1 TO RETRIES
xerr = FormatTrack(drive, track, head)
IF xerr = 0 THEN EXIT FOR
NEXT
IF xerr THEN FormatDisk = xerr: EXIT FUNCTION
NEXT
NEXT
FormatDisk = 0
END FUNCTION
FUNCTION FormatTrack (drive, track, head)
'{Initialize address field for each sector on this track}
FOR sec = 1 TO Info.ST
AddrField(sec).track = CHR$(track)
AddrField(sec).head = CHR$(head)
AddrField(sec).sector = CHR$(sec)
AddrField(sec).bytesec = CHR$(2) '{bytecode 2 = 512-byte sector}
NEXT
ireg.ax = &H500 + Info.ST '{format track with sectors/track}
ireg.cx = (track * 256) + 1 '{track to format,start with sector 1}
ireg.dx = (head * 256) + drive '{head,drive}
ireg.es = VARSEG(AddrField(1)) '{point to address field data}
ireg.bx = VARPTR(AddrField(1))
INTERRUPTX &H13, ireg, oreg
cf = oreg.flags AND 1 '{cf=1 if disk error}
IF cf THEN
e& = oreg.ax
IF e& < 0 THEN e& = e& + 65536
FormatTrack = e& \ 256 '{return with status byte}
ResetFDC drive
ELSE ireg.ax = &H400 + Info.ST '{ok, verify track integrity-}
INTERRUPTX &H13, ireg, oreg '{-optional but recommended on format}
cf = oreg.flags AND 1 '{cf=1 if disk error}
IF cf THEN
e& = oreg.ax
IF e& < 0 THEN e& = e& + 65536
FormatTrack = e& \ 256 '{return with status byte}
ResetFDC drive
ELSE
FormatTrack = 0 '{format ok}
END IF
END IF
END FUNCTION
SUB InitFormatParms (media)
'{set up media's format data}
Info.OEM = "IBM 3.1" '{avoid chan